package com.doumi.biz.qadev.api.util;

import com.doumi.biz.qadev.api.bean.UserBaseInfo;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * Created by YDZ on 2019/10/23.
 */
@Slf4j
public class StringFormatUtils {
    public String getPullSql(UserBaseInfo userBaseInfo){
        StringBuffer sb =new StringBuffer("SELECT user_id FROM zpt_chonggou_new.sy_rck_resume_full s WHERE (job_prefer_detail LIKE '%{\"city_id\":" + userBaseInfo.getCityId() + ",________________________________________,\"job_type_id\":" + userBaseInfo.getJobTypeId() + "}%'"+
                "\tOR job_prefer_detail LIKE '%{\"city_id\":"+userBaseInfo.getCityId()+",__________________________________________,\"job_type_id\":"+userBaseInfo.getJobTypeId()+"}%' )" +
                "                AND prefer_city_id LIKE '%"+userBaseInfo.getCityId()+"%' AND (prefer_job_type_id LIKE '%,"+userBaseInfo.getJobTypeId()+",%'OR prefer_job_type_id LIKE '%,"+userBaseInfo.getJobTypeId()+"]%' OR prefer_job_type_id LIKE '%["+userBaseInfo.getJobTypeId()+"]%' OR prefer_job_type_id LIKE '%["+userBaseInfo.getJobTypeId()+",%' )");

        if(userBaseInfo.getGender()!=0) {
            sb.append(" AND gender = ").append(userBaseInfo.getGender());
        }
        if(userBaseInfo.getIdentity()!=0) {
            sb.append(" AND identify = ").append(userBaseInfo.getIdentity());
        }

        if(userBaseInfo.getDegree()==1 || userBaseInfo.getDegree()==100) {
            sb.append(" AND degree >= ").append(userBaseInfo.getDegree());
        }else if (userBaseInfo.getDegree()==8){
            sb.append(" AND degree >= 3").append(" AND degree < 100");
        }else {
            sb.append(" AND degree >= ").append(userBaseInfo.getDegree()).append(" AND degree < 100");

        }
        if(userBaseInfo.getAgeStart()==0) {
            userBaseInfo.setAgeStart(18);
        }
        sb.append(" AND age >= ").append(userBaseInfo.getAgeStart());
        if(userBaseInfo.getAgeEnd()==0) {
            userBaseInfo.setAgeEnd(55);;
        }
        sb.append(" AND age <=").append(userBaseInfo.getAgeEnd());

        sb.append(" ORDER BY basic_full_time_score DESC,user_id DESC limit 500");
        log.info("获取的sql为sb={}",sb.toString());
        return sb.toString();
    }
    public String getPullSql(UserBaseInfo userBaseInfo,Integer page){
        StringBuffer sb =new StringBuffer("SELECT user_id FROM zpt_chonggou_new.sy_rck_resume_full s WHERE (job_prefer_detail LIKE '%{\"city_id\":" + userBaseInfo.getCityId() + ",________________________________________,\"job_type_id\":" + userBaseInfo.getJobTypeId() + "}%'"+
                "\tOR job_prefer_detail LIKE '%{\"city_id\":"+userBaseInfo.getCityId()+",__________________________________________,\"job_type_id\":"+userBaseInfo.getJobTypeId()+"}%' )" +
                "                AND prefer_city_id LIKE '%"+userBaseInfo.getCityId()+"%' AND (prefer_job_type_id LIKE '%,"+userBaseInfo.getJobTypeId()+",%'OR prefer_job_type_id LIKE '%,"+userBaseInfo.getJobTypeId()+"]%' OR prefer_job_type_id LIKE '%["+userBaseInfo.getJobTypeId()+"]%' OR prefer_job_type_id LIKE '%["+userBaseInfo.getJobTypeId()+",%' )");

        if(userBaseInfo.getGender()!=0) {
            sb.append(" AND gender = ").append(userBaseInfo.getGender());
        }
        if(userBaseInfo.getIdentity()!=0) {
            sb.append(" AND identify = ").append(userBaseInfo.getIdentity());
        }

        if(userBaseInfo.getDegree()==1 || userBaseInfo.getDegree()==100) {
            sb.append(" AND degree >= ").append(userBaseInfo.getDegree());
        }else if (userBaseInfo.getDegree()==8){
            sb.append(" AND degree >= 3").append(" AND degree < 100");
        }else {
            sb.append(" AND degree >= ").append(userBaseInfo.getDegree()).append(" AND degree < 100");

        }
        if(userBaseInfo.getAgeStart()==0) {
            userBaseInfo.setAgeStart(18);
        }
        sb.append(" AND age >= ").append(userBaseInfo.getAgeStart());
        if(userBaseInfo.getAgeEnd()==0) {
            userBaseInfo.setAgeEnd(55);;
        }
        sb.append(" AND age <=").append(userBaseInfo.getAgeEnd());
        sb.append(" ORDER BY basic_full_time_score DESC,user_id DESC");
        sb.append(" limit 50");
//        if (page==0){
//            sb.append(" limit 50");
//        }else {
//            sb.append(" limt "+(page*10-1)+",10");
//        }
        log.info("获取的sql为sb={}",sb.toString());
        return sb.toString();
    }


    public String getPullSqlBaseInfo(UserBaseInfo userBaseInfo){
        StringBuffer sb =new StringBuffer("SELECT user_id,age,identify,gender,degree FROM zpt_chonggou_new.sy_rck_resume_full s WHERE (job_prefer_detail LIKE '%{\"city_id\":" + userBaseInfo.getCityId() + ",________________________________________,\"job_type_id\":" + userBaseInfo.getJobTypeId() + "}%'"+
                "\tOR job_prefer_detail LIKE '%{\"city_id\":"+userBaseInfo.getCityId()+",__________________________________________,\"job_type_id\":"+userBaseInfo.getJobTypeId()+"}%' )" +
                "                AND prefer_city_id LIKE '%"+userBaseInfo.getCityId()+"%' AND (prefer_job_type_id LIKE '%,"+userBaseInfo.getJobTypeId()+",%'OR prefer_job_type_id LIKE '%,"+userBaseInfo.getJobTypeId()+"]%' OR prefer_job_type_id LIKE '%["+userBaseInfo.getJobTypeId()+"]%' OR prefer_job_type_id LIKE '%["+userBaseInfo.getJobTypeId()+",%' )");

        if(userBaseInfo.getGender()!=0) {
            sb.append(" AND gender = ").append(userBaseInfo.getGender());
        }
        if(userBaseInfo.getIdentity()!=0) {
            sb.append(" AND identify = ").append(userBaseInfo.getIdentity());
        }

        if(userBaseInfo.getDegree()==1 || userBaseInfo.getDegree()==100) {
            sb.append(" AND degree >= ").append(userBaseInfo.getDegree());
        }else if (userBaseInfo.getDegree()==8){
            sb.append(" AND degree >= 3").append(" AND degree < 100");
        }else {
            sb.append(" AND degree >= ").append(userBaseInfo.getDegree()).append(" AND degree < 100");

        }
        if(userBaseInfo.getAgeStart()==0) {
            userBaseInfo.setAgeStart(18);
        }
        sb.append(" AND age >= ").append(userBaseInfo.getAgeStart());
        if(userBaseInfo.getAgeEnd()==0) {
            userBaseInfo.setAgeEnd(55);;
        }
        sb.append(" AND age <=").append(userBaseInfo.getAgeEnd());
        sb.append(" ORDER BY basic_full_time_score DESC,user_id DESC");
//        sb.append(" limit 50");
//        if (page==0){
//            sb.append(" limit 50");
//        }else {
//            sb.append(" limt "+(page*10-1)+",10");
//        }
        log.info("获取的sql为sb={}",sb.toString());
        return sb.toString();
    }

    public String stringArrayToString(List<String> lists){
        StringBuffer sb = new StringBuffer("[");
        for (int i = 0; i <lists.size()-1;  i++) {
            sb.append(lists.get(i).trim()).append(",");
        }
        sb.append(lists.get(lists.size()-1).trim());
        sb.append("]");
        return null;
    }
}
